using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Tomahawk.Runtime.Serialization;
using Tomahawk.Runtime.Rendering.Objects;

namespace Tomahawk.Runtime.Logic
{
    public class XMaterialSpriteComponent : XRenderableComponent
    {

        MaterialQuad quadModel;

        /// <summary>
        /// Constructor
        /// </summary>
        protected XMaterialSpriteComponent()
        {
            //default priority is: Scene
            this.RenderStage = Engine.RenderingStages.Scene;
        }

        #region "Serializable properties"

        /// <summary>
        /// The name of the material to be used
        /// </summary>
        [XmlElement("Material")]
        public string Material = "";

        #endregion

        #region "Public properties"

        /// <summary>
        /// Returns the rendering object used to render the sprite
        /// </summary>
        public MaterialQuad QuadModel
        {
            get { return quadModel; }
        }

        #endregion

        /// <summary>
        /// Initialization
        /// </summary>
        protected override void OnInitialize()
        {
            base.OnInitialize();

            this.quadModel = new MaterialQuad(this.Material);
            this.SceneNode.Attach(this.quadModel);

        }

        protected override void OnUpdate(float elapsedTime)
        {
            base.OnUpdate(elapsedTime);
        }

        #region "Readyness"

        /// <summary>
        /// Returns true when all the resource dependant objects are ready
        /// </summary>
        protected override bool checkResourcesReady()
        {
            return base.checkResourcesReady() &&
                this.quadModel.IsReady;
        }

        #endregion

    }

}
